home *** CD-ROM | disk | FTP | other *** search
- /*
- File: DiskEntry.h
-
- Copyright: © 1991-1994 by Apple Computer, Inc.
- All rights reserved.
-
- Part of the AOCE Sample SMSAM Package. Consult the license
- which came with this software for your specific legal rights.
-
- */
-
-
-
- #ifndef __DISKENTRY__
- #define __DISKENTRY__
-
- #ifndef __TYPES__
- #include "Types.h"
- #endif
-
- #ifndef __GMTTIME__
- #include "GMTTime.h"
- #endif
-
- #ifndef __DIRECTOBJECT__
- #include "DirectObject.h"
- #endif
-
- class ostream;
- class TAbstractFile;
-
- /***********************************|****************************************/
-
- typedef unsigned long EntryID;
-
- class TLogEntry : public TDirectObject
- {
- public:
-
- static const EntryID kInvalidID;
-
- TLogEntry ();
- TLogEntry ( const TLogEntry& );
- virtual ~TLogEntry ();
-
- TLogEntry& operator = ( const TLogEntry& );
- Boolean operator == ( const TLogEntry& ) const;
- Boolean operator != ( const TLogEntry& ) const;
-
- EntryID GetID () const;
- void GetTimeStamp ( TTimeStamp& ) const;
- const TTimeStamp& GetTimeStamp () const;
-
- virtual unsigned long GetTextLength () const;
- virtual void GetText ( char* buffer, unsigned long size ) const;
- virtual char* CreateText () const;
-
- virtual Boolean WriteTo ( TAbstractFile& ) const;
- virtual Boolean ReadFrom ( TAbstractFile& );
-
- virtual ostream& operator >> ( ostream& ) const;
-
- protected:
-
- virtual const char* GetClass () const; // all subclasses must override
-
- private: EntryID fID;
- TTimeStamp fTime;
- char* fCache;
-
- friend class TDiskLog;
- };
-
- /***********************************|****************************************/
-
- class TTestEntry : public TLogEntry
- {
- public: TTestEntry (); // has random length
- TTestEntry ( unsigned long length );
- TTestEntry ( const TTestEntry& );
- virtual ~TTestEntry ();
-
- TTestEntry& operator = ( const TTestEntry& );
- Boolean operator == ( const TTestEntry& ) const;
- Boolean operator != ( const TTestEntry& ) const;
-
- virtual Boolean WriteTo ( TAbstractFile& ) const;
- virtual Boolean ReadFrom ( TAbstractFile& );
-
- virtual ostream& operator >> ( ostream& ) const;
-
- protected:
-
- static const unsigned long kChunkSize;
-
- virtual const char* GetClass () const; // all subclasses must override
-
- static unsigned long RandomLength ( unsigned long min = 0, unsigned long max = 128 );
- static void FillBuffer ( char*, unsigned long );
- static Boolean VerifyBuffer ( char*, unsigned long );
-
- private: unsigned long fLength;
- };
-
- /***********************************|****************************************/
-
- class TErrorEntry : public TLogEntry
- {
- public: TErrorEntry ();
- TErrorEntry ( const char* file, unsigned long line, const char* message = nil );
- TErrorEntry ( const TErrorEntry& );
- virtual ~TErrorEntry ();
- TErrorEntry& operator = ( const TErrorEntry& );
-
- virtual unsigned long GetTextLength () const;
- virtual void GetText ( char* buffer, unsigned long size ) const;
- virtual char* CreateText () const;
-
- virtual Boolean WriteTo ( TAbstractFile& ) const;
- virtual Boolean ReadFrom ( TAbstractFile& );
-
- virtual ostream& operator >> ( ostream& ) const;
-
- protected:
-
- virtual const char* GetClass () const; // all subclasses must override
- virtual unsigned long GetString ( char* buffer ) const; // returns length
- virtual Boolean Write ( const char*, TAbstractFile& ) const;
- virtual Boolean Read ( char*&, TAbstractFile& ) const;
-
- private: char* fFile;
- unsigned long fLine;
- char* fMessage;
- };
-
- /***********************************|****************************************/
- /***********************************|****************************************/
-
- #pragma push
- #pragma segment DiskLog
-
- /***********************************|****************************************/
-
- inline
- TLogEntry::~TLogEntry ()
- {
- delete fCache;
- }
-
- /***********************************|****************************************/
-
- inline EntryID
- TLogEntry::GetID () const
- {
- return fID;
- }
-
- /***********************************|****************************************/
-
- inline void
- TLogEntry::GetTimeStamp ( TTimeStamp& time ) const
- {
- time = fTime;
- }
-
- /***********************************|****************************************/
-
- inline const TTimeStamp&
- TLogEntry::GetTimeStamp () const
- {
- return fTime;
- }
-
- /***********************************|****************************************/
-
- #pragma pop
-
- #endif // __LOGENTRY__